package com.jz.community.modulemine.wifi.task;

import android.app.Activity;

import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;
import com.jz.community.modulemine.wifi.bean.WifiDayInfo;

import java.util.HashMap;

/**
 * Created by Tony.Fan on 2018/5/29 09:16
 */
public class UpdateWifiDayTask extends RxTask<String, Integer, WifiDayInfo> {

    private Activity activity;
    private ITaskCallbackListener taskListener;

    public UpdateWifiDayTask(Activity activity,
                             ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected WifiDayInfo doInBackground(String... params) {
        // 执行请求
        String result = OkHttpUtil.post(Constant.UPDATE_WIFI_DAY_URL, getParam(params[0]), true);
        WifiDayInfo info = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            info = JsonUtils.parseObject(result, WifiDayInfo.class);
        }
        return info;
    }

    @Override
    protected void onPostExecute(WifiDayInfo result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }


    /**
     * 获取请求所需的参数
     *
     * @param
     * @return
     */
    private HashMap<String, Object> getParam(String mobile) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("mobile", mobile);
        return params;
    }

}